import {ClientTypes, SocketManager} from "../socket";
import {ClientManager} from "../socket/events/client";
import Oasis from "../utils/oasis";

const Router = require('koa-router');
const router = new Router({
    prefix: 'passport',
});

/**
 * 核心签名算法
 */
router.post('/sign', async (ctx: any) => {
    const params = ctx.inputs;
    const manager: SocketManager = ctx.io.manager;
    const ct = manager.getClient(ClientTypes.oasis_client);
    if (!ct) {
        return ctx.json({message: "获取签名失败,签名服务不可用"}, 400)
    }
    const client: ClientManager = ct;
    let signStr = Oasis.getSignStr(params);
    const res: any = await client.getOasisSign(signStr);
    if (!res.ok) {
        return ctx.json({message: "获取签名失败，签名失败", data: res}, 400)
    }
    return ctx.json({data: res}, 200)
});

export default router;

